package com.bckj.fastboot.log;

import cn.hutool.core.util.StrUtil;
import com.bckj.fastboot.log.model.LogRecord;

import java.util.*;

public class LogContext {
    private static final ThreadLocal<List<LogRecord>> logHolder = new ThreadLocal<>();

    public static void addLog(Long bizId, String template, Object... params) {
        LogRecord record = new LogRecord();
        record.setBizId(bizId);
        record.setContent(StrUtil.format(template, params));
        addLog(record);
    }

    public static void addLog(LogRecord log) {
        List<LogRecord> list = logHolder.get();
        if (list == null) {
            list = new ArrayList<>();
            logHolder.set(list);
        }
        list.add(log);
    }

    public static List<LogRecord> getLog() {
        return logHolder.get();
    }

    public static void clear() {
        logHolder.remove();
    }
}

    
	